#include <iostream>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <strings.h>
#include <unistd.h>


int main()
{
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
    struct sockaddr_in local;
    bzero(&local, sizeof local);

    local.sin_family = AF_INET;
    local.sin_addr.s_addr = INADDR_ANY;
    local.sin_port = htons(8080);

    int n = bind(sockfd, (struct sockaddr*)&local, sizeof(local));
    if (n < 0);
    
    n = listen(sockfd, 8);
    if (n < 0);


    struct sockaddr_in client;
    socklen_t len = sizeof(client);
    int fd = accept(sockfd, (struct sockaddr*)&client, &len);
    if (fd < 0);

    char buffer[1024];
    n = recv(fd, buffer, 1024, 0);
    buffer[n] = 0;
    std::cout << buffer << std::endl;

    close(fd);
    close(sockfd);

    return 0;
}